#include "endingpanel.h"
#include <QPainter>


EndingPanel::EndingPanel(bool isLord, bool isWin , QWidget *parent) : QWidget{parent}
{
    m_bk.load(":/images/gameover.png");
    setFixedSize(m_bk.size());

    // 显示用户玩家的角色以及对应的游戏状态
    m_title = new QLabel(this);
    if (isLord && isWin) { // 地主赢
        m_title->setPixmap(QPixmap(":/images/lord_win.png"));
    } else if (isLord && !isWin) { // 地主输
        m_title->setPixmap(QPixmap(":/images/lord_fail.png"));
    } else if (!isLord && isWin) { // 农民赢
        m_title->setPixmap(QPixmap(":/images/farmer_win.png"));
    } else if (!isLord && !isWin) { // 农民输
        m_title->setPixmap(QPixmap(":/images/farmer_fail.png"));
    }
    m_title->move(125, 125); // 移动到中心位置

    // 设置分数面板
    m_scorePanel = new ScorePanel(this);
    m_scorePanel->move(75, 230);
    m_scorePanel->setFixedSize(260, 160);
    m_scorePanel->setMyFontColor(ScorePanel::Red);
    m_scorePanel->setMyFontSize(18);

    // 设置继续游戏按钮
    m_continue = new QPushButton(this);
    QString style = R"(QPushButton{border-image: url(:/images/button_normal.png)}
                       QPushButton:hover{border-image: url(:/images/button_hover.png)}
                       QPushButton:pressed{border-image: url(:/images/button_pressed.png)})";
    m_continue->setStyleSheet(style);
    m_continue->setFixedSize(231, 48);
    m_continue->move(84, 429);
    // 点击继续游戏按钮，则给分数结算面板发射信号
    connect(m_continue, &QPushButton::clicked, this, &EndingPanel::continueGame);
}

// 设置玩家的分数
void EndingPanel::setPlayerScore(int left, int right, int me)
{
    m_scorePanel->setScores(left, right, me);
}

void EndingPanel::paintEvent(QPaintEvent *ev)
{
    Q_UNUSED(ev);
    QPainter p(this);
    p.drawPixmap(rect(), m_bk);
}
